#include "BayesianFilter.h"
#include "Archivo.h"

#include <map>
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

#define BAYES_MAGIC_NUMBER  0xBA7351A4

#define SERIALIZER_VERSION_MINOR 0
#define SERIALIZER_VERSION_MAYOR 1

#define SERIALIZER_VERSION_FIELD ((SERIALIZER_VERSION_MAYOR << 8) + SERIALIZER_VERSION_MINOR)

#define __int32 int32_t
#define __int8  int8_t

class BayesianFilterSerializer
{
friend class BayesianFilter;
	
public:
	BayesianFilterSerializer(BayesianFilter& filter);
	~BayesianFilterSerializer(void);

	void Serialize   (string dataFile, string matrixFile);
	void Deserialize (string dataFile, string matrixFile);

private:
	BayesianFilter& filter;

	void WriteHeader (ofstream& f, bool data, __int32 id);
	void WriteCommit (string fileName);

	void DumpTagsWords(string fileName,__int32 fileID);
	void DumpMatrix(string fileName,__int32 fileID);

	__int32 CheckHeaders(string fileName,ifstream& file, bool* data);
	__int32	RebuildTags (ifstream& data);
	void	RebuildWords(__int32 tagCount, ifstream& data,ifstream& matrix);
};
